﻿namespace Indigo.RenderingTemplateDemo
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint.WebControls;
    using System.Web.UI;

    public static class ControlExtensions
    {
       public static IEnumerable<T> FindControls<T>(this Control control) where T: Control
        {
            if (control is T)
            {
                yield return (T)control;
            }

            foreach (Control ctrl in control.Controls)
            {
                if (ctrl is T)
                {
                    yield return (T)ctrl;
                }

                foreach (var innerCtrl in ctrl.FindControls<T>())
                {
                    yield return innerCtrl;
                }
            }
        }
    }
}
